<html>
<head><meta charset="utf-8"><title>figure out if a path is mutable · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html">figure out if a path is mutable</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218187429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218187429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218187429">(Nov 29 2020 at 00:07)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w">  </span><span class="k">mut</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Point</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span>: <span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">y</span>: <span class="mi">20</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">mp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">p</span><span class="p">;</span><span class="w"></span>

<span class="k">use</span><span class="p">(</span><span class="n">mp</span><span class="p">.</span><span class="n">x</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>Where/How does the compiler figure out that the <code>Place</code> associated with <code>mp.x</code> (<code>Place(mp, projections: [Deref, Field])</code>  is mutable?</p>



<a name="218200950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218200950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218200950">(Nov 29 2020 at 07:38)</a>:</h4>
<p>I guess you need to access the associated <code>LocalDecl</code>?</p>



<a name="218201011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218201011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218201011">(Nov 29 2020 at 07:40)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">body</span><span class="p">.</span><span class="n">local_decls</span><span class="p">[</span><span class="n">place</span><span class="p">.</span><span class="n">local</span><span class="p">].</span><span class="n">mutability</span><span class="w"></span>
</code></pre></div>



<a name="218202193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218202193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218202193">(Nov 29 2020 at 08:19)</a>:</h4>
<p>I think that wouldn't work with something like where <code>t1</code> itself isn't mutable or a mut-ref but rather contains a mut ref</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">);</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">t1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">t</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="p">(</span><span class="n">t1</span><span class="p">.</span><span class="mf">0.0</span><span class="w"> </span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="218203325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203325">(Nov 29 2020 at 08:57)</a>:</h4>
<p>You could maybe get the <code>LocalDecl</code> for <code>t.0</code> through the <code>Place::projection</code>?</p>



<a name="218203368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203368">(Nov 29 2020 at 08:58)</a>:</h4>
<p>Wait I can? <span aria-label="open mouth" class="emoji emoji-1f62e" role="img" title="open mouth">:open_mouth:</span></p>



<a name="218203381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203381">(Nov 29 2020 at 08:59)</a>:</h4>
<p>You have a <code>ProjectionElem::Field</code> which itself contains a <code>Local</code></p>



<a name="218203385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203385">(Nov 29 2020 at 08:59)</a>:</h4>
<blockquote>
<p><code>Place(mp, projections: [Deref, Field])</code></p>
</blockquote>
<p>This is what you have, right?</p>



<a name="218203432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203432">(Nov 29 2020 at 09:00)</a>:</h4>
<p>Yeah I have that</p>



<a name="218203441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203441">(Nov 29 2020 at 09:01)</a>:</h4>
<p>Wait nevermind <code>Field</code> doesn't contain a <code>Local</code></p>



<a name="218203442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203442">(Nov 29 2020 at 09:01)</a>:</h4>
<p>It contains a <code>Ty</code></p>



<a name="218203482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203482">(Nov 29 2020 at 09:02)</a>:</h4>
<p>Yeah index and type</p>



<a name="218203616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203616">(Nov 29 2020 at 09:08)</a>:</h4>
<p>The mutability checks seem to be done in <a href="https://github.com/rust-lang/rust/blob/c4fe25d8613a32dcd71e5258c22ff5685f12d4c3/compiler/rustc_mir/src/borrow_check/mod.rs#L973-L1027">https://github.com/rust-lang/rust/blob/c4fe25d8613a32dcd71e5258c22ff5685f12d4c3/compiler/rustc_mir/src/borrow_check/mod.rs#L973-L1027</a></p>



<a name="218203664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218203664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218203664">(Nov 29 2020 at 09:09)</a>:</h4>
<p>Which has this whole <code>is_mutable</code> mess <span aria-label="grinning face with smiling eyes" class="emoji emoji-1f601" role="img" title="grinning face with smiling eyes">:grinning_face_with_smiling_eyes:</span> <a href="https://github.com/rust-lang/rust/blob/c4fe25d8613a32dcd71e5258c22ff5685f12d4c3/compiler/rustc_mir/src/borrow_check/mod.rs#L2156-L2306">https://github.com/rust-lang/rust/blob/c4fe25d8613a32dcd71e5258c22ff5685f12d4c3/compiler/rustc_mir/src/borrow_check/mod.rs#L2156-L2306</a></p>



<a name="218204134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/figure%20out%20if%20a%20path%20is%20mutable/near/218204134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/figure.20out.20if.20a.20path.20is.20mutable.html#218204134">(Nov 29 2020 at 09:25)</a>:</h4>
<p>I'll read through what's happening here. thank you <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>